package com.monster.datasourcejob.datax.writer.impl;

import com.monster.datasourcejob.datax.writer.Writer;
import com.monster.datasourcejob.model.Field;

import java.util.List;

/**
 * description:
 *
 * @author Yuanml on 2021/6/30 17:55
 */
public class HiveWriter implements Writer {
    @Override
    public String genContent() {
        return null;
    }

    @Override
    public String genFieldList(List<Field> fields) {
        StringBuilder fieldsBuilder = new StringBuilder();
        int size = fields.size();
        for (int i = 0; i < size - 1; i++) {
            toJsonStyle(fieldsBuilder, fields.get(i));
            fieldsBuilder.append(",\n");
        }
        toJsonStyle(fieldsBuilder, fields.get(size-1));
        return fieldsBuilder.toString();
    }

    private void toJsonStyle(StringBuilder fieldsBuilder, Field field) {
        fieldsBuilder.append("{\n\t\"name\": \"").append(field.getName()).append("\",");
        fieldsBuilder.append("\n\t\"type\": \"").append(field.getType()).append("\",\n}");
    }
}
